<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>员工管理</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>

<script type="text/javascript">
	function doAdd(){
		//alert("增加...");
		//$("input[name='sId']").val('-1');
		$('#addStandardWindow').form('clear');
		$('#addStandardWindow *').trigger('blur');// 离焦
		$('#addStandardWindow').window("open").window('setTitle', '添加通知');
		$("input[name='nId']").val('-1'); 
	}
	
	function getQueryParams(queryParams) {  
		var searchcontent = $('#searchcontent').val();
	     queryParams.nTopic = searchcontent;  
	     return queryParams;  
	   
	 }  
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        getQueryParams(queryParams);  
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
    function doExport(){
    	$.messager.alert('提示', "正在完善中...",'info')
    }
	 function doSearch(){			
		reloadgrid();
	}
	
	function doEdit(){
		var rowData = $('#grid').datagrid('getSelected');  
        
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
	        $("input[name='nId']").val(rowData.nId);
	 		$('#nPriority').combobox('select', rowData.nPriority);
			$("input[name='nTopic']").val(rowData.nTopic);
			$("input[name='nSender']").val(rowData.nSender);
			$("input[name='nAddress']").val(rowData.nAddress);
			
		
			
		
 			
			/* $('#sStatus').combobox('setValue', rowData.sStatus);
	 		$('#dept').combobox('select', rowData.sDeptId);
 */
			// 弹出窗口
			  
			$("#addStandardWindow").window('open').window('setTitle', '修改员工');
        } 
	}

	

	
	// 定义列
	var columns = [ [   {
		field : 'fContent',
		title : '反馈内容',
		width : 300,	
	},  {
		field : 'fStaff',
		title : '反馈人',
		width : 60,
	},  {
		field : 'fDateTime',
		title : '反馈时间',
		width : 100,
		formatter:formatterDate
	},  {
		field : 'fIsProcess',
		title : '是否处理',
		width : 60,
		formatter:formatterYouXianJi

	},  {
		field : 'fPOpinion',
		title : '处理意见',
		width : 110,
	},  {
		field : 'fPStaff',
		title : '处理人',
		width : 110,
		
	},  {
		field : 'fPDateTime',
		title : '处理时间',
		width : 100,
		formatter:formatterDate
	}, {
		field : 'fId',
		title : '操作',
		width : 160,
		formatter:formatterFuQuan
	} ] ];
	
	function formatterYouXianJi(value,row,index){
		if(value==0){
			return "未处理";
		}if(value==1){
			return "已处理";
		}
	}
	
	function formatterDate(value,row,index){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(parseInt(value) * 1000);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}

	
	function formatterFuQuan(value,row,index){
		if(row.fIsProcess==0){
			return "<a onclick=doFuQuan("+index+") href=#>处理</a>";	
		}
		
	}
	
	function doDel(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	    if(row){ 
	
		     $.messager.confirm("操作提示", "确认删除 当前记录？", function (data) {  
		            if (data) {  
		            	$.post("${pageContext.request.contextPath}/page.noticedel.ashx?nId="+row.nId,function(data){
			    			
			    			if(data.status == "1"){
			    				// 成功
			    				$.messager.alert('消息','操作成功 ','info');
			    				reloadgrid();
			    				
			    			
			    			}else{
			    					$.messager.alert('消息','<br>操作失败','info');
			    				
			    			}
			    				
			    		}); 
		            }  
		            else {  
		                 
		            }  
		        }); 


		}
	}
	
	function doFuQuan(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	    
	    $('#addStandardWindow').window('open');
	    $('#fId').val(row.fId);
	    
	    $('#fPOpinion').focus();
	}
	
	
	
	function formatterSex(value,row,index){
		if(row.sSex==1){
			return "男";
		}else if(row.sSex==0){
			return "女";
		}
	}
	

	
	function formatterStatus(value,row,index){
		if(row.sStatus==1){
			return "离职";
		}else if(row.sStatus==0){
			return "在职";
		}
	}
	$(function(){
		$('#add').click(doAdd);
		$('#edit').click(doEdit);
		$('#search').click(doSearch);
		$('#export').click(doExport);
	});
	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/page.feedbackList.ashx",
			idField : 'fId',
			columns : columns,
			pageList: [10,25,50],
			pagination:true,
			view:myview,
			emptyMsg:"<font size=5>暂无记录</font>",
			singleSelect: true,
			
			
		});
		
		//初始化员工窗口
		$('#addStandardWindow').window({
            title: '处理意见',
            width: 400,
            modal: true,
            shadow: true,
            closed: true,
            height: 230,
            resizable:false
            
        });
		
	
		
		//提交表单
		$('#save').click(function(){
			
			var a = $('#fPOpinion').val().trim();
				// 校验
				if(a!=null&&a!=''){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/page.updateFeedback.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#addStandardWindow').window('close');
							
							$('#addStandardWindow').form('clear');
							$('#addStandardWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else{
							$.messager.alert('消息','操作失败 ','info');
						}
							
					});
				}else{
					$.messager.alert("提示", "请输入处理意见");
				}
				
			});	
		
		
	});
	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});
	$.extend($.fn.validatebox.defaults.rules, {   
	    //验证汉字   
	    CHS: {   
	        validator: function (value) {   
	            return /^[\u0391-\uFFE5]+$/.test(value);   
	        },   
	        message: '只能输入汉字'  
	    },   
	    //移动手机号码验证   
	    mobile: {//value值为文本框中的值   
	        validator: function (value) {   
	            var reg = /^1[3|4|5|7|8|9]\d{9}$/;   
	            return reg.test(value);   
	        },   
	        message: '输入手机号码格式不准确.'  
	    },   
	    //国内邮编验证   
	    zipcode: {   
	        validator: function (value) {   
	            var reg = /^[1-9]\d{5}$/;   
	            return reg.test(value);   
	        },   
	        message: '邮编必须是非0开始的6位数字.'  
	    },   
	    //用户账号验证(只能包括 _ 数字 字母)    
	    account: {//param的值为[]中值   
	        validator: function (value, param) {   
	            if (value.length < param[0] || value.length > param[1]) {   
	                $.fn.validatebox.defaults.rules.account.message = '用户名长度必须在' + param[0] + '至' + param[1] + '范围';   
	                return false;   
	            } else {   
	                if (!/^[\w]+$/.test(value)) {   
	                    $.fn.validatebox.defaults.rules.account.message = '用户名只能数字、字母、下划线组成.';   
	                    return false;   
	                } else {   
	                    return true;   
	                }   
	            }   
	        }, message: ''  
	    }   
	})
	

	
	
		
</script>	
</head>
<body class="easyui-layout" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	
	<div class="easyui-window" title="员工详情" id="addStandardWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			</div>
		</div>
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sform">
				<!-- <table class="table-edit" width="90%" align="center">
					<tr class="title">
						<td colspan="4">处理意见</td>
					</tr> -->
					
				
					<input name="fId" id="fId" type="hidden" class="easyui-validatebox"/>
							
					<!-- <tr> -->
						
						<textarea name="fPOpinion" id="fPOpinion" cols="50" rows="7" style=" border:solid 3px #E2E2E2;line-height:16px; padding:5px;"></textarea>
					
					<!-- </tr> -->
					
			
					<!-- </table> -->
			</form>
		</div>
	</div>
	
		<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
		<!-- 	<a href="#" id="add" class="easyui-linkbutton" iconCls="icon-add" plain="true" >增加</a>
			<a href="#" id="edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a> -->
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;反馈内容: <input id="searchcontent" class="easyui-textbox" style="width:80px">
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
		
		</div>
	</div>
</body>
</html>